/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jmooc.service;

import com.jmooc.dao.AnswerDao;
import com.jmooc.entity.Answer;
import com.jmooc.entity.Question;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author Group
 */
@Stateless
public class AnswerService implements Serializable {
     
    @EJB
    private AnswerDao answerDao;
    
    // Return randomly ordered answers
    // Useless. Done in entity.
    /*public List<Answer> getAllByQuestion(Question question) {
        List<Answer> result = answerDao.getAllByQuestion(question);
        
        for (int i = 0; i < 5 * result.size(); ++i) {
            int pos1 = (int) Math.ceil(Math.random() * result.size())-1;
            int pos2 = (int) Math.ceil(Math.random() * result.size())-1;
            
            Answer tmp = result.get(pos1);
            
            result.set(pos1, result.get(pos2));
            result.set(pos2, tmp);
        }
        
        return result;
    }*/
    
    public void create(Answer answer) {
        answerDao.create(answer);
    }
    
}
